from django import template

register = template.Library()


def key(item, string):
    return item.get(string, '')


def label_class(value, arg):
    return value.label_tag(attrs={'class': arg})


def field_class(value, arg):
    value.field.widget.attrs['class'] = arg
    return value


def sort_dict(value, arg):
    return value[arg]


register.filter('sort_dict', sort_dict)
register.filter('key', key)
register.filter('label_class', label_class)
register.filter('field_class', field_class)